//LoginServlet.java
package com.ylaihui.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class LoginServlet extends BaseServlet {
    protected void login(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        if("lisimmy".equals(username) && "123456".equals(password)){
            System.out.println("login succ.");

            Cookie username1 = new Cookie("username", username);
            //cookie保存一周
            username1.setMaxAge( 60 * 60 * 24 * 7);

            resp.addCookie(username1);

        }else{
            System.out.println("login fail!");
        }
    }
}
